

namespace NodeBasedSkillEditor.Model.Node.RT
{
    public class Node_Rescale_RT : RT_Node
    {
        public RT_SingleValuePort Value_RT;

        public RT_SingleValuePort Start_RT;

        public RT_SingleValuePort End_RT;

        public RT_SingleValuePort NewStart_RT;

        public RT_SingleValuePort NewEnd_RT;

        public RT_SingleValuePort Clamp_RT;

        public RT_SingleValuePort Result_RT;

        public Node_Rescale_RT(Node_Rescale sourceData, RT_DAG parentDag) : base(sourceData, parentDag)
        {
            Value_RT = new RT_SingleValuePort(EPortIOType.Input, sourceData.Value, this);

            Start_RT = new RT_SingleValuePort(EPortIOType.Input, sourceData.Start, this);

            End_RT = new RT_SingleValuePort(EPortIOType.Input, sourceData.End, this);

            NewStart_RT = new RT_SingleValuePort(EPortIOType.Input, sourceData.NewStart, this);

            NewEnd_RT = new RT_SingleValuePort(EPortIOType.Input, sourceData.NewEnd, this);

            Clamp_RT = new RT_SingleValuePort(EPortIOType.Input, sourceData.Clamp, this);

            Result_RT = new RT_SingleValuePort(EPortIOType.Output, sourceData.Result, this);
            Result_RT.OnGetValue = GetResult;
        }

        public AValue GetResult(DAG_Executor executor)
        {
            float value = Value_RT.GetValue(executor).ToScalar().Item2;
            float start = Start_RT.GetValue(executor).ToScalar().Item2;
            float end = End_RT.GetValue(executor).ToScalar().Item2;
            float newStart = NewStart_RT.GetValue(executor).ToScalar().Item2;
            float newEnd = NewEnd_RT.GetValue(executor).ToScalar().Item2;
            bool clamp = Clamp_RT.GetValue(executor).ToBoolean().Item2;
            float result = XDFLib.XMath.Rescale(value, start, end, newStart, newEnd, clamp);

            Result_RT.SourceValue.SetScalar(result);
            return Result_RT.SourceValue;
        }
    }
}